<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <script src="js/jquery-3.2.1.min.js"></script>
    <script src="js/vue.js"></script>

    <link rel="stylesheet" href="css/mui.min.css">
    <link rel="stylesheet" type="text/css" href="css/app.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <title></title>

    <style>
        input[type=button] {
            background: #f2675f;
            color: #FFFFFF;
            position: absolute;
            width: 100%;
        }
        
        div {
            text-align: center;
            font-family: "微软雅黑";
        }
    </style>
</head>
<header class="mui-bar mui-bar-nav" style="background: #f2675f;display: none;">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: #fff;"></a>
    <h1 class="mui-title" style="font-family:'微软雅黑';color: #fff;">确认订单</h1>
</header>

<body>
    </br>

    <div class="username"></div>
    <img class="haedphoto" style="
    height: 100px;
    width: 100px;
   
    position: relative;
    left: 36%;
    top: 13px;
"></div>
    </br>
    </br>

    <input type="button" value="视频支付" onclick='player()' />

    <div class="m">
        <p class="vjs-no-js" style="
    width: 640px;
    height: 32px;
    position: absolute;
    z-index: 999;
">



            该视频为付费视频！请付费后观看

        </p>
        <video id="my-video" class="video-js" src="" controls preload="auto" width="640" height="264" poster="images/banner1.png" data-setup="{}">
			<source type="video/mp4" src="" id="gg">
		
		  </video>

        <script type="text/javascript">
            /*
                                                                                                		
                                                                                                		

                                                                                                	document.getElementsByClassName("vjs-modal-dialog-content")[0].innerHTML="该视频为付费视频！请付费后播放"；*/
            /*var myPlayer = this;
            myPlayer.play();*/
        </script>
    </div>
    </br>
    </br>
    </br>
</body>

</html>

<script src="js/WechatCchuaPayVideo.js"></script>
<link href="css/video-js.css" rel="stylesheet">
<!-- If you'd like to support IE8 -->

<style>
    .m {
        width: 640px;
        height: 264;
        margin-left: auto;
        margin-right: auto;
        margin-top: 100px;
    }
</style>

<script type="text/javascript" Author="Cchua">
    window.onload = function() {


        if (localStorage.openId == undefined) {
            WechatNewLogin();
        } else {
            console.log("存在openid")
                /*alert("存在openid")*/
            WechatLogin();


        }
    }







    function WechatLogin() {




        $.ajax({
            type: "post",
            contentType: "application/json", //必须有
            url: 'http://igo.vrdete.com/api/wechat/openidata',



            data: "{'openid':'" + localStorage.openId + "'}",
            success: function(data) {
                console.log(data);

                var sta = data.htmlState;
                if (sta.match("Error")) {
                    WechatNewLogin();
                } else {
                    $(".haedphoto")[0].src = data.dataResultObj.headimgurl;

                    $(".username")[0].innerText = data.dataResultObj.nickName;

                }

            },
            error: function(xhr, type, errorThrown) {
                //异常处理；
                console.log(type);
            }


        });





















    }














    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }

    function WechatNewLogin() {
        var appid;
        var myurl = GetQueryString("code");
        if (myurl != null && myurl.toString().length > 1) {
            var usercode = GetQueryString("code");
            console.log("已经获取到Code：" + GetQueryString("code"));
            console.log("即将调用后台获取用户数据");








            $.ajax({
                type: "post",
                contentType: "application/json", //必须有
                url: 'http://igo.vrdete.com/api/wechat/postwcode',



                data: "{'openid':'" + localStorage.openId + "'}",
                success: function(data) {

                    console.log(JSON.stringify(data));

                    console.log("openId:" + JSON.stringify(data.dataResultObj.openId

                    ));

                    localStorage.openId = data.dataResultObj.openId;
                    localStorage.userId = data.dataResultList[0].id;

                    $(".haedphoto")[0].src = data.dataResultObj.headimgurl;

                    $(".username")[0].innerText = data.dataResultObj.nickName;



                    /*localStorage 后面接的是Key值  让后赋值*/

                },
                error: function(xhr, type, errorThrown) {
                    //异常处理；
                    console.log(type);
                }

            });























        } else {
            console.log("未获取到Code")
            console.log("WechatLogin:Go")
            var tourl = "http%3a%2f%2figo.vrdete.com%2fmp%2fCchuaVideo.html";







            $.ajax({
                type: "post",
                contentType: "application/json", //必须有
                url: 'http://igo.vrdete.com/api/wechat/authorize',



                data: "{'openid':'" + localStorage.openId + "'}",
                success: function(data) {

                    console.log("in mui.ajax type post");
                    console.log("你已取得Appid:" + data.dataResultObj.AppId);

                    appid = data.dataResultObj.AppId;

                    window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appid + '&redirect_uri=' + tourl + '&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect '

                    console.log(data);

                },
                error: function(xhr, type, errorThrown) {
                    //异常处理；
                    console.log(type);
                }


            });































        }
    }
</script>